﻿package model.dao.entity;

import java.util.Date;
import java.util.List;

import model.dao.AbstractDAO;
import model.entity.Member;

public class MemberDAO  extends AbstractDAO<Member, Integer>{
	public MemberDAO() {
		super(Member.class);
	}
	public boolean signup(String phone){
		boolean result = false;
		List<Member> listMember = this.selectAll();
		for(Member m : listMember){
			if(m.getPhone().equals(phone)){
				result = true;
			}
		}
		return result;
	}
	
	public boolean registry(String name, String phone, Date brithday){
		List<Member> listMember = this.selectAll();
		for(Member m : listMember){
			if(m.getPhone().equals(phone)){
				return false;
			}
		}
			
		MemberDAO memberDAO = new MemberDAO();
		MemberLevelDAO  memberLevelDAO = new MemberLevelDAO();
		Member m1 = new Member();
		m1.setName(name);
		m1.setBrithday(brithday);
		m1.setJoinDate(new Date());
		m1.setPhone(phone);
		m1.setPointAccumulated(1000);
		
		m1.setMemberLevel(memberLevelDAO.findReference(1));
		memberDAO.persist(m1);
		return true;
	}
}
